<template>
  <div>
    <el-card>
      <el-form :inline="true" :model="query" label-width="130px" size="small">
        <el-form-item label="组建公司意愿等级: " class="query-form-item">
          <el-select
            v-model="query.type"
            placeholder="请选择意愿等级"
            @change="onSubmit"
            clearable
          >
            <el-option clearable label="全球" value="1"></el-option>
            <el-option clearable label="省级" value="2"></el-option>
            <el-option clearable label="市级" value="3"></el-option>
            <el-option clearable label="县级" value="4"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="意愿状态: " class="query-form-item">
          <el-select
            v-model="query.auditstatus"
            placeholder="请选择意愿状态"
            @change="onSubmit"
            clearable
          >
            <el-option clearable label="待审核" value="0"></el-option>
            <el-option clearable label="通过" value="1"></el-option>
            <el-option clearable label="驳回" value="2"></el-option>
            <el-option clearable label="已生效" value="3"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="申请商家账号: " class="query-form-item">
          <el-input
            v-model="query.mobile"
            placeholder="请输入商家账号"
            prefix-icon="el-icon-search"
            @keyup.enter.native="onSubmit"
            clearable
          ></el-input>
        </el-form-item>
        <!-- 查询框 -->
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-refresh"
            @click="onRest"
          ></el-button>
          <el-button type="primary" icon="el-icon-search" @click="onSubmit"
            >查询</el-button
          >
        </el-form-item>
      </el-form>
      <!-- table表单 -->
      <el-table
        ref="singleTable"
        :data="tableData"
        v-loading="loading"
        style="width: 100%"
      >
        <el-table-column
          label="序号"
          type="index"
          align="center"
          width="50"
          fixed
        >
        </el-table-column>
        <el-table-column prop="auditstatus" align="center" label="意愿状态">
          <template slot-scope="scope">
            <span v-if="scope.row.auditstatus == 0">待审核</span>
            <span v-else-if="scope.row.auditstatus == 1">通过</span>
            <span v-else-if="scope.row.auditstatus == 2">驳回</span>
            <span v-else-if="scope.row.auditstatus == 3">已生效</span>
            <span v-else>无</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="typename"
          align="center"
          label="组建公司意愿等级"
        >
          <!-- <template slot-scope="scope">
            <span v-if="scope.row.type == 1">全球</span>
            <span v-else-if="scope.row.type == 2">省级</span>
            <span v-else-if="scope.row.type == 3">市级</span>
            <span v-else-if="scope.row.type == 4">县级</span>
            <span v-else>无</span>
          </template> -->
        </el-table-column>
        <el-table-column prop="mobile" align="center" label="申请商家账号">
          <template slot-scope="scope">
            <span v-if="scope.row.mobile">{{ scope.row.mobile }}</span>
            <span v-else>无</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="companyname"
          align="center"
          label="申请商家公司名称"
        >
          <template slot-scope="scope">
            <span v-if="scope.row.companyname">{{
              scope.row.companyname
            }}</span>
            <span v-else>无</span>
          </template>
        </el-table-column>
        <el-table-column align="center" label="操作" fixed="right" width="230">
          <template slot-scope="scope">
            <el-button
              type="primary"
              :disabled="scope.row.auditstatus != 0"
              size="mini"
              @click="applyVisibleShow(scope.row)"
              >组建新公司</el-button
            >
            <el-button
              type="danger"
              size="mini"
              :disabled="scope.row.auditstatus != 0"
              @click="
                (dialogTableVisible = true), rejectionApplication(scope.row)
              "
              >驳回申请</el-button
            >
          </template>
        </el-table-column>
      </el-table>

      <!-- 驳回的dialog -->
      <el-dialog
        title="请填写驳回原因"
        :visible.sync="dialogTableVisible"
        :close-on-click-modal="false"
      >
        <el-form>
          <el-form-item label="驳回原因：">
            <el-input
              type="textarea"
              style="width: 600px"
              v-model="reasons"
            ></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogTableVisible = false">取 消</el-button>
          <el-button type="primary" @click="applySubmit(2)">确 定</el-button>
        </div>
      </el-dialog>
      <el-dialog
        title="组建新公司"
        :visible.sync="applyVisible"
        :before-close="hideApplyForm"
        width="60%"
        top="5vh"
        v-dialogDrag
        :close-on-click-modal="false"
      >
        <el-card>
          <el-form label-width="140px">
            <el-form-item
              style="border-bottom: 1px solid #ebeef5"
              label-width="0px"
            >
              <el-form-item
                label="头像："
                style="width: 30%; display: inline-block"
              >
                <el-popover
                  v-if="companyDetail.companyurl"
                  placement="right"
                  trigger="hover"
                >
                  <img
                    :src="companyDetail.companyurl"
                    style="width: 400px; border-radius: 3px"
                  />
                  <img
                    slot="reference"
                    :src="companyDetail.companyurl"
                    style="
                      max-height: 80px;
                      max-width: 50px;
                      border-radius: 5px;
                    "
                  />
                </el-popover>
                <span v-else>无</span>
              </el-form-item>
            </el-form-item>
            <!-- 行政区划 -->

            <el-form-item label="行政区域：">
              <span>{{ companyDetail.intentionarea || "无" }}</span>
            </el-form-item>

            <el-form-item
              style="border-bottom: 1px solid #ebeef5"
              label-width="0px"
            >
              <el-form-item
                label="商户ID："
                style="width: 50%; display: inline-block"
              >
                <span>{{ companyDetail.apllywishid || "无" }}</span>
              </el-form-item>
              <el-form-item
                label="公司名称："
                style="width: 50%; display: inline-block"
              >
                <span>{{ companyDetail.companyname || "无" }}</span>
              </el-form-item>
            </el-form-item>
            <el-form-item
              style="border-bottom: 1px solid #ebeef5"
              label-width="0px"
            >
              <el-form-item
                label="手机号："
                style="width: 50%; display: inline-block"
              >
                <span>{{ companyDetail.mobile || "无" }}</span>
              </el-form-item>
              <el-form-item
                label="总业绩："
                style="width: 50%; display: inline-block"
              >
                <span>{{ companyDetail.totalperformance || "0" }}</span>
              </el-form-item>
            </el-form-item>
          </el-form>
        </el-card>
        <span
          slot="footer"
          class="dialog-footer"
          style="text-align: center !important"
        >
          <el-button type="info" size="mini" @click="applyVisible = false"
            >取消</el-button
          >
          <el-button type="primary" size="mini" @click="applySubmit(1)"
            >同意</el-button
          >
        </span>
      </el-dialog>
      <el-pagination
        class="pagination-container"
        background
        :page-size="query.pageSize"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        layout="total,sizes,prev, pager, next, jumper"
        :current-page="query.currentPage"
        :page-sizes="[5, 10, 20, 30, 50]"
        :total="totalNumber"
      ></el-pagination>
    </el-card>
  </div>
</template>
<script>
import {
  getCreateCompanyList, //列表数据获取
  createCompanyConfirm, //同意组建公司
} from "../../api/alliance";
export default {
  data() {
    return {
      tableData: [], //列表集合
      tableList: {}, //详情框信息
      query: {
        currentPage: 1,
        pageSize: 5,
        type: "",
        auditstatus: "", //审核状态:0.审核中  1.通过  2.驳回
        mobile: "",
      },
      dataList: [],
      companyDetail: {},
      totalNumber: 0,
      loading: false,
      dataList: [],
      disabled: false,
      dialogTableVisible: false,
      dialogFormVisible: false,
      reasons: "",
      formLabelWidth: "120px",
      applyVisible: false, //组建新公司弹框
    };
  },
  methods: {
    // 组建新公司对话框显示
    applyVisibleShow(row) {
      this.companyDetail = row;
      this.applyVisible = true;
    },
    // 同意或驳回
    applySubmit(type) {
      const obj = {
        apllywishid: this.companyDetail.apllywishid,
        auditstatus: type,
      };
      if (type == 2) {
        if (this.reasons.trim() == "") {
          return this.$message.error("请输入驳回理由");
        }
        obj.rejectreason = this.reasons;
      }
      createCompanyConfirm(obj)
        .then((data) => {
          if (data.code != 0) {
            this.$message.error(data.message);
            return false;
          }
          this.$message.success("操作成功");
          type == 1
            ? (this.applyVisible = false)
            : (this.dialogTableVisible = false);
          this.reasons = "";
          this.onRest();
        })
        .catch((err) => {
          this.dialogTableVisible = false;
        });
    },
    //申请弹窗关闭
    hideApplyForm() {
      this.applyVisible = !this.applyVisible;
      this.companyDetail = {};
    },
    // 列表数据获取
    getMbUserAapplyMgrAudit() {
      this.loading = true;

      getCreateCompanyList(this.query)
        .then((data) => {
          // console.log(data);
          if (data.code != 0) {
            this.$message.error(data.message);
            this.loading = false;
            return false;
          }
          this.tableData = data.data.list || [];
          this.totalNumber = data.data.totalNumber || 0;
          console.log(this.tableData, "意愿列表");
          setTimeout(() => {
            this.loading = false;
          }, 300);
        })
        .catch((err) => {
          this.loading = false;
          this.tableData = [];
        });
    },

    //刷新
    onRest() {
      this.query = {
        currentPage: 1,
        promotioncategoryid: "",
        auditstatus: "", //审核状态:0.审核中  1.通过  2.驳回
        effectivestatus: "", // 生效状态：0.未生效  1.已生效
        account: "",
        enterprisename: "", //企业名称
        pageSize: 5,
      };

      this.getMbUserAapplyMgrAudit();
    },
    //查询
    onSubmit() {
      this.query.currentPage = 1;
      this.getMbUserAapplyMgrAudit();
      // console.log('submit!');
    },
    // 驳回信息
    rejectionApplication(val) {
      console.log(val);
      this.companyDetail = val;
    },

    handleCurrentChange(val) {
      this.query.currentPage = val;
      //scrollTo(0, 800);
      this.getMbUserAapplyMgrAudit();
    },
    handleSizeChange(val) {
      this.query.pageSize = val;
      this.getMbUserAapplyMgrAudit();
    },
  },

  mounted() {},
  created() {
    this.getMbUserAapplyMgrAudit();
  },
};
</script>
